﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Charting;
using Telerik.Charting.Styles;
using System.Drawing;

namespace BSCMFF.Web.UserControls
{
    /// <summary>
    /// Survey question chart.
    /// </summary>
    /// <remarks></remarks>
    public partial class SurveyQuestionChart : System.Web.UI.UserControl
    {
        /// <summary>
        /// Gets or sets the question.
        /// </summary>
        /// <value>The question.</value>
        /// <remarks></remarks>
        public string Question { get; set; }
        /// <summary>
        /// Gets or sets the results.
        /// </summary>
        /// <value>The results.</value>
        /// <remarks></remarks>
        public Dictionary<string, int> Results { get; set; }


        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks></remarks>
        protected void Page_Load(object sender, EventArgs e)
        {
            ChartSeries chs = new ChartSeries();
            chs.Type = ChartSeriesType.Pie;
            
            Dictionary<string, int>.Enumerator en = Results.GetEnumerator();

            while (en.MoveNext())
            {
                ChartSeriesItem chi = new ChartSeriesItem();
                chi.Name = en.Current.Key;
                chi.YValue = en.Current.Value;
                chi.Label.TextBlock.Text = en.Current.Value.ToString() ;
                chs.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
                chs.Items.Add(chi);
            }
            chs.Appearance.FillStyle.MainColor = Color.Transparent;
            chs.Appearance.FillStyle.FillType = FillType.Solid;
            RadChartQuestion.Series.Add(chs);
            RadChartQuestion.ChartTitle.TextBlock.Text = Question;
        }
    }
}